#ifndef NXWZ_H
#define NXWZ_H
#include "stm8l15x.h"
//#include "stdbool.h"
#include "define.h"	


/*typedef struct
{
	uint8_t uiIdentifier;
	uint8_t uiaMessageID[2];
	uint8_t uiaMessageAttribute[2];
	uint8_t uiaEquipID[6];
	uint8_t uiaMessageSN[2];
	
	uint8_t uiType;
	uint8_t uiaTime[6];
	uint8_t uiSampleCycle;
	uint8_t uiEndIndicate;
}MessageHead_TypeDef;


typedef enum
{
	PRESS_SENSOR = 0x20,
	LIQUID_LEVEL_SENSOR = 0x30,
	FLOW_METER	= 0x92,
	WATER_METER = 0x93
}Peripheral_TypeDef;

typedef struct
{
	Peripheral_TypeDef sePeripheral;
	uint8_t uiLen;
	uint8_t uiMeterVol;
	uint8_t uiEquipVol;
	uint8_t uiSignal;
}MeterBasicInfor_TypeDef;

typedef struct
{
	uint8_t uiaInstantFlow[4];
	uint8_t uiaFowardFlow[6];
	uint8_t uiaReverseFlow[6];
	uint8_t uiaPressure[2];
	uint8_t uiaAlarm[2];
}SingleDataInfor_TypeDef;


typedef struct
{
	MessageHead_TypeDef stMessageHead;
	MeterBasicInfor_TypeDef stMeterBasicInfor;
	Peripheral_TypeDef sePeripheral;
	uint8_t uiCount;
	SingleDataInfor_TypeDef stSingleDataInfor[50];
	uint8_t uiXor;
	uint8_t uiIdentifier;	
	//uint8_t EscapeData[0];
}EquipBasicData_TypeDef;


typedef struct
{
	MessageHead_TypeDef stMessageHead;
	Peripheral_TypeDef sePeripheral;
	uint8_t uiCount;
	SingleDataInfor_TypeDef stSingleDataInfor[22];
	uint8_t uiXor;
	uint8_t uiIdentifier;	
	//uint8_t EscapeData[0];
}EquipTestData_TypeDef;

typedef struct
{
	MessageHead_TypeDef stMessageHead;
	MeterBasicInfor_TypeDef stMeterBasicInfor;
	Peripheral_TypeDef sePeripheral;
	uint8_t uiCount;
	SingleDataInfor_TypeDef stSingleDataInfor[1];
	uint8_t uiXor;
	uint8_t uiIdentifier;	
	//uint8_t EscapeData[0];
}TriggerData_TypeDef;


typedef struct
{
	//MessageHead_TypeDef stMessageHead;
	uint8_t uiIdentifierHead;
	uint8_t uiaMessageID[2];
	uint8_t uiaMessageAttribute[2];
	uint8_t uiaEquipID[6];
	uint8_t uiaMessageSN[2];
	
	uint8_t uiaAuthenCode[17];
	uint8_t uiXor;
	uint8_t uiIdentifierTail;	
	//uint8_t EscapeData[0];
}Authen_TypeDef;


typedef struct
{
	uint8_t uiaFirstTime[5];
	//MeterBasicInfor_TypeDef stMeterBasicInfor;
	uint8_t uiMeterVol;
	uint8_t uiaEquipVol[2];
	uint8_t uiEquipCSQ;
	SingleDataInfor_TypeDef stFirstSingleDataInfor[50];
	uint8_t uiaSecondTime[5];
	SingleDataInfor_TypeDef stSecondSingleDataInfor[22];
	uint8_t uiXor;
}UnsentData_TypeDef;*/

uint8_t FillReportDataPacket(void);
uint8_t XOR_Check(uint8_t *puiSrc, uint16_t uiLen);
//uint16_t EscapeDataNum(uint8_t *puiSrc, uint16_t uiLen);
//void EscapeDataHandle(uint8_t *puiSrc, uint16_t uiPreAdjustLen, uint16_t uiAfterAdjustLen);
uint8_t N720_RecvData(uint8_t *pBuf, uint16_t uiLen);
//void ReceiveEscapeHandle(uint8_t *pBuf, uint16_t puiLen);
void SaveUnsendData(uint16_t data_addr);
uint8_t read_unsend_data(void);
void SendUnsendData(void);
//static void time_add_second(uint8_t *bcd_time,int32_t second);
void time_triming(RTC_DateTypeDef BS_DateStr, RTC_TimeTypeDef BS_TimeStr);
int32_t get_second_diff(uint8_t *bcd_time1,uint8_t *bcd_time2);
uint8_t check_leap_year(uint8_t u8year);




#endif

